package cn.lzb.book.server.api.book;

import cn.lzb.book.server.api.AbstractBaseApi;
import cn.lzb.book.server.entity.BaseResult;
import cn.lzb.book.server.entity.dto.BookInfo;
import cn.lzb.book.server.entity.dto.BookPageQuery;
import cn.lzb.book.server.entity.dto.Ids;
import cn.lzb.book.server.entity.vo.BookDetailVo;
import cn.lzb.book.server.entity.vo.BookPageVo;
import cn.lzb.book.server.service.IBookService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

/**
 * @author liuzhibo
 * @date 2024/8/28 15:46
 **/
@Api(tags = "图书管理接口")
@RestController
@RequestMapping("/book")
public class BookApi extends AbstractBaseApi {

    private final IBookService bookService;

    public BookApi(IBookService bookService) {
        this.bookService = bookService;
    }

    @PostMapping("/save")
    public BaseResult<String> save(@RequestBody BookInfo book) {
        bookService.save(book, this.getCurrentUser());
        return BaseResult.success();
    }

    @PostMapping("/update")
    public BaseResult<String> update(@RequestBody BookInfo book) {
        bookService.update(book, this.getCurrentUser());
        return BaseResult.success();
    }

    @PostMapping("/delete/ids")
    public BaseResult<String> deleteIds(@RequestBody Ids ids) {
        bookService.deleteByIds(ids, this.getCurrentUser());
        return BaseResult.success();
    }

    @GetMapping("/query/details")
    public BaseResult<BookDetailVo> queryDetails(@RequestParam Long id) {
        BookDetailVo bookDetailVo = bookService.queryDetails(id);
        return BaseResult.success(bookDetailVo);
    }

    @PostMapping("/query/page")
    public BaseResult<IPage<BookPageVo>> queryPage(@RequestBody BookPageQuery pageQuery) {
        IPage<BookPageVo> queryPage = bookService.queryPage(pageQuery);
        return BaseResult.success(queryPage);
    }

}
